local thbattle__nazilin_tanbao = fk.CreateSkill {

  name = "thbattle__nazilin_tanbao",

  tags = {},

}
thbattle__nazilin_tanbao:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__nazilin_tanbao.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardsJudged = {}
    while true do
      local judge = {
        who = player,
        reason = thbattle__nazilin_tanbao.name,
        pattern = ".|.|spade,club",
        skipDrop = true,
      }
      room:judge(judge)
      local card = judge.card
      if card.color == Card.Black then
        table.insert(cardsJudged, card)
      elseif room:getCardArea(card) == Card.Processing then
        room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, thbattle__nazilin_tanbao.name, nil, true, player)
      end
      if not judge:matchPattern() or player.dead or not room:askToSkillInvoke(player, { skill_name = thbattle__nazilin_tanbao.name }) then
        break
      end
    end
    cardsJudged = table.filter(cardsJudged, function(c) return room:getCardArea(c.id) == Card.Processing end)
    if #cardsJudged > 0 then
      room:obtainCard(player, cardsJudged, true, fk.ReasonJustMove)
    end
  end,
})


return thbattle__nazilin_tanbao
